package com.shop.cereshop.business.dl.logic.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shop.cereshop.business.dao.dl.CereShopCarouselDAO;
import com.shop.cereshop.business.dl.logic.domain.CereShopCarousel;
import com.shop.cereshop.business.dl.logic.service.CereShopCarouselService;
import com.shop.cereshop.business.dl.logic.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: dlshop
 * 描述：
 * @author: 我好帅
 * @create: 2021-07-06 20:11
 **/
@Service
public class CereShopCarouselServiceImpl implements CereShopCarouselService {
    @Autowired
    private CereShopCarouselDAO cereShopCarouselDAO;

    @Override
    public ResultInfo select(Integer page,Integer row) {
        PageHelper.startPage(page,row);
        List<CereShopCarousel> list = cereShopCarouselDAO.select();
        PageInfo pageInfo = new PageInfo(list);
        return new ResultInfo(pageInfo);
    }

    @Override
    public ResultInfo add(CereShopCarousel obj) {
        int i = cereShopCarouselDAO.insertSelective(obj);
        if (i > 0) {
            return new ResultInfo();
        } else {
            return new ResultInfo(400, "添加失败");
        }
    }

    @Override
    public ResultInfo update(CereShopCarousel obj) {
        int i = cereShopCarouselDAO.updateByPrimaryKeySelective(obj);
        if (i > 0) {
            return new ResultInfo();
        } else {
            return new ResultInfo(400, "修改失败");
        }
    }

    @Override
    public Integer getMaxId() {
        return cereShopCarouselDAO.getMaxId();
    }

    @Override
    public ResultInfo delete(Long carousel) {
        int i = cereShopCarouselDAO.deleteByPrimaryKey(carousel);
        if (i > 0) {
            return new ResultInfo();
        } else {
            return new ResultInfo(400, "删除失败");
        }
    }

    @Override
    public ResultInfo enableDisable(Long carousel, Byte state) {
        String mess="";
        if (state==1){
            state=0;
            mess="禁用";
        }else if (state==0){
            state=1;
            mess="启用";
        }
        int i = cereShopCarouselDAO.enableDisable(carousel,state);
        if (i > 0) {
            return new ResultInfo();
        } else {
            return new ResultInfo(400, mess+"失败");
        }
    }

    @Override
    public ResultInfo selectById(Long carousel) {
        CereShopCarousel c = cereShopCarouselDAO.selectByPrimaryKey(carousel);
        return new ResultInfo(c);
    }
}
